package com.itheima.d2_upd1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    public static void main(String[] args)throws Exception {
        System.out.println("服务器启动...");
        DatagramSocket datagramSocket = new DatagramSocket(8888);

        DatagramPacket packet = new DatagramPacket(new byte[1024*64], 1024*64);

        while(true) {
            datagramSocket.receive(packet);
            String data = new String(packet.getData(), 0, packet.getLength());
            System.out.println("收到客户端消息：" + data);
            System.out.println(packet.getAddress().getHostAddress());
            System.out.println(packet.getPort());
            System.out.println("-----------------------");
        }



    }
}
